<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    *{margin: 0;padding: 0}
    
    * {
            padding: 0;
            margin: 0;
        }

        li {
            list-style: none;
        }

        .header {
            height: 160px;
            background: darkseagreen;
        }

        .menu {
            height: 90px;
            background-color: grey;
        }

        #tabBox>.content {
            height: 500px;
            text-align: center;
            line-height: 500px;
            border: 1px solid #000;
        }

        .footer {
            height: 500px;
            background-color: #000;
        }

        #slideMenu {
            position: fixed;
            right: 30px;
            top: 50%;
            transform: translateY(-50%);
            padding: 5px;
            border-radius: 3px;
            background: cornsilk;
        }

        #slideMenu li {
            line-height: 30px;
            margin: 10px;
            border: 1px solid #000;
            padding: 5px;
        }

        #slideMenu .active {
            background: #6ff;
            color: #fff;
        }
    </style>
</head>
<body>
        <div class="header">

            </div>
            <div class="menu">
        
            </div>
            <div id="tabBox">
                <div class="content">01</div>
                <div class="content">02</div>
                <div class="content">03</div>
                <div class="content">04</div>
                <div class="content">05</div>
                <div class="content">06</div>
                <div class="content">07</div>
                <div class="content">08</div>
                <div class="content">09</div>
                <div class="content">10</div>
            </div>
            <div class="footer"></div>
        
            <ul id="slideMenu">
                <li class="active">tab01</li>
                <li>tab02</li>
                <li>tab03</li>
                <li>tab04</li>
                <li>tab05</li>
                <li>tab06</li>
                <li>tab07</li>
                <li>tab08</li>
                <li>tab09</li>
                <li>tab10</li>
            </ul>
    <script>
     var tabbox=document.getElementById("tabBox");
     var contlist=tabbox.getElementsByClassName("content");
     var slidemenu=document.getElementById("slideMenu")
     var menulist=slidemenu.getElementsByTagName("li")
     var footera=document.getElementsByClassName("footer")[0];
    //  滑动时导航跳动
    window.onscroll=function(){
    var scolltop=document.documentElement.scrollTop||document.body.scrollTop
    console.log(scolltop)
    for(var i=0;i<contlist.length;i++){
       var start=contlist[i].offsetTop;   
    //    console.log(contlist[i+1])
       if(i==contlist.length-1){
        var end=footera.offsetTop
       }
       else{
        var end=contlist[i+1].offsetTop;
       }
       if(scolltop+200>start&&scolltop+200<end){
               for(var j=0;j<menulist.length;j++){
                   menulist[j].className=""
               }
                menulist[i].className="active"
           }
    }
    }

    // 点击侧导航调到相应的模块   
for(let i=0;i<menulist.length;i++){//循环每一个模块区间
        //  每一个menu加点击事件
    menulist[i].onclick=function(){
            var start=document.documentElement.scrollTop
            var end=contlist[i].offsetTop
            var speed=(end-start)/10
        if(end>start){
            clearInterval(time)
            var time=setInterval(fn,100)
            function fn(){
                document.documentElement.scrollTop=start+speed
                start=document.documentElement.scrollTop
                    if(start>end){
                    clearInterval(time)
                    document.documentElement.scrollTop=end
                    }
            }
        }
        else{
            clearInterval(time)
            var time=setInterval(fn1,100)
            function fn1(){
                document.documentElement.scrollTop=start+speed
                start=document.documentElement.scrollTop
                    if(start<end){
                    clearInterval(time)
                    document.documentElement.scrollTop=end
                    }
            }
        }
    }
}
    </script>
</body>
</html>